- Java PDF Generation with IText
- Getting Started with IText PDF API for Java
- Java IText: Document
- Java IText: Chunk
- Java IText: Phrase
- Java IText: Paragraph
- Java IText: Chapter + Section
- Java IText: Anchor (link)
- Java IText: List
- Java IText: Table
- Java IText: Image
- Java IText: Superscript + Subscript
- Java IText: Underline + Strikethrough
- Java IText: Font
- Java IText: Modifying Existing PDF Documents
Java IText: Document
Jakob Jenkov |
The com.itextpdf.text.Document class in IText represents a PDF document. It is one of the core
classes in IText. If you need to generate a PDF document from scratch, you will use the
Document class.
First you must create a Document instance. Then you must open it. After that you
add content to the document. Finally you close the Document instance.
Here is a simple code example:
import com.itextpdf.text.Document;
import com.itextpdf.text.DocumentException;
import com.itextpdf.text.Paragraph;
public class DocumentExample {
public static void main(String[] args) {
Document document = new Document();
try {
document.open();
document.add(new Paragraph("A Hello World PDF document."));
document.close(); // no need to close PDFwriter?
} catch (DocumentException e) {
e.printStackTrace();
}
}
}
Notice how no PDFWriter is created in this example. If you want to flush the generated
document to an OutputStream (file, network etc.), you must use a PDFWriter.
There is an example of how to use a PDFWriter, in the Getting Started text.
| Tweet | |
Jakob Jenkov | |









